//上拉加载
var buttom = false;

$(document).on("swipeup",function(){
		var winH =$(window).height();
		var myScroll = $(window).scrollTop();
		if(($(document).height()<= winH||($('body').height() - myScroll) <= winH )&&!buttom){
			console.log("到底了");
			buttom=true;
			$(".slideToMore").hide();
			$(".loading").show();
			more();
		}
});

//加载更多
function more(){
	
	var currentPage = $("#currentPage").val();
	var totalPage = $("#totalPage").val();
	var nextPage = 0;
	//目前页面的商品数量
	var currentProductNum = $(".productList").find(".product-container").length;
	//回到第一页
	if(parseInt(currentProductNum)<=20){
		currentPage = 1;
	}
	//是否已经到最后 
	if(parseInt(currentPage)+1<=parseInt(totalPage)){
		nextPage = parseInt(currentPage)+1;
		getPlatformIndexxMsg(nextPage);
	}else{
		$(".slideToMore").text("到底了");
		$(".loading").hide();
		$(".slideToMore").show();
	}
}

function getPlatformIndexxMsg(nextPage){
	$(".slideToMore").hide();
	$(".loading").show();
	$.ajax({
	type:"get",
	url:base_url+"customer/getMorePlatformIndexxMsg",
	data:{"pageNum":nextPage},
	success:function(data){
		$(".loading").hide();
		$(".slideToMore").show();
		var platformActivityClassifyMsgs = data.resultSet;
		for(var i=0;i<platformActivityClassifyMsgs.length;i++){
			var productType = platformActivityClassifyMsgs[i].product.productType;
			var html = "";
			if(productType=='0'){
				//为零售专柜的商品
				html = 	'<div class="product-container">'
							+'<div class="product" data-productId="'+platformActivityClassifyMsgs[i].product.productId+'" data-productType="lingshou">'
							+'<a>'
								+'<div class="product-img">'
									+'<img class="p-img lazy" data-src="'+platformActivityClassifyMsgs[i].product.productSurfacePlot+'" data-load="false"/>'
									+'<div class="share-awards">'
										+'<span>分享消费奖</span>'
										+'<span class="f14">'+platformActivityClassifyMsgs[i].tuiguangCommission+'元</span>'
									+'</div>'
									+'<div class="amount-info">'
										+'<div class="amount">'
											+'<span>预售<span>'+parseInt(platformActivityClassifyMsgs[i].productItem.stock+platformActivityClassifyMsgs[i].product.salesVolume)+'</span>件</span>'
											+'<span>仅剩'+platformActivityClassifyMsgs[i].productItem.stock+'件</span>'
										+'</div>'
									+'</div>'
								+'</div>'
								+'<p class="product-name text-2">'
								+	platformActivityClassifyMsgs[i].product.productName											
								+'</p>';
				if(platformActivityClassifyMsgs[i].product.platformPrice<platformActivityClassifyMsgs[i].product.marketPrice){
					html = html +'<p class="product-price">'
								+'	<span class="price f14">'+platformActivityClassifyMsgs[i].product.platformPrice+'</span>'
								+'</p>'
								+'<p class="old-price">'
								+'	<del>'+platformActivityClassifyMsgs[i].product.marketPrice+'元</del>'
								+'	<span class="finished">已成交'+platformActivityClassifyMsgs[i].product.salesVolume+'件</span>'												
								+'</p>'
				}else{
					html = html +'<p class="product-price">'
								+'	<span class="price f14">'+platformActivityClassifyMsgs[i].product.platformPrice+'</span>'
								+'</p>'
								+'<p class="old-price">'
								+'	<span class="finished">已成交'+platformActivityClassifyMsgs[i].product.salesVolume+'件</span>'
								+'</p>'
				}

				html = html	+'</a>'
							+'</div>'
						+'</div>'
			}else if(productType=='4'){
				//为一起拼团的商品
				html = 	'<div class="product-container">'+
							'<div class="product" data-productId="'+platformActivityClassifyMsgs[i].product.productId+'" data-productType="pingtuan">'+
							'<a>'+
								'<div class="product-img">'+
									'<img class="p-img lazy" data-src="'+platformActivityClassifyMsgs[i].product.productSurfacePlot+'" data-load="false"/>'+
									'<div class="share-awards">'+
										'<span>分享消费奖</span>'+
										'<span class="f14">'+platformActivityClassifyMsgs[i].tuiguangCommission+'元</span>'+
									'</div>'+
									'<div class="amount-info">'+
										'<div class="amount">'+
											'<span>预售<span>'+parseInt(platformActivityClassifyMsgs[i].productItem.stock+platformActivityClassifyMsgs[i].product.salesVolume)+'</span>件</span>'+
											'<span>仅剩'+platformActivityClassifyMsgs[i].productItem.stock+'件</span>'+
										'</div>'+
									'</div>'+
								'</div>'+
								'<p class="product-name text-2">'+
									+platformActivityClassifyMsgs[i].product.productName+	
								'</p>'
				if(platformActivityClassifyMsgs[i].product.platformPrice<platformActivityClassifyMsgs[i].product.marketPrice){
					html = html + 
								'<p class="product-price">'+
									'<span class="price f14">'+platformActivityClassifyMsgs[i].product.platformPrice+'</span>'+
									'<span class="discount floatRight">'+platformActivityClassifyMsgs[i].product.openingNumber+'人团</span>'+
								'</p>'+
								'<p class="old-price">'+
									'<del>'+platformActivityClassifyMsgs[i].product.marketPrice+'元</del>'+
									'<span class="finished">已成交'+platformActivityClassifyMsgs[i].product.salesVolume+'件</span>'+
								'</p>'
				}else{
					html = html + 
								'<p class="product-price">'+
									'<span class="price f14">'+platformActivityClassifyMsgs[i].product.platformPrice+'</span>'+
									'<span class="discount floatRight">'+platformActivityClassifyMsgs[i].product.openingNumber+'人团</span>'+
								'</p>'+
								'<p class="old-price">'+
									'<span class="finished">已成交'+platformActivityClassifyMsgs[i].product.salesVolume+'件</span>'+
								'</p>'
				}			
				html = html+
							'</a>'+
							'</div>'+
						'</div>'
			}else if(productType=='6'){
				//折扣特卖
				html = 	'<div class="product-container">'+
								'<div class="product" data-productId="'+platformActivityClassifyMsgs[i].product.productId+'" data-productType="zhekou">'+
								'<a>'+
									'<div class="product-img">'+
										'<img class="p-img lazy" data-src="'+platformActivityClassifyMsgs[i].product.productSurfacePlot+'" data-load="false"/>'+
										'<div class="share-awards">'+
											'<span>分享消费奖</span>'+
											'<span class="f14">'+platformActivityClassifyMsgs[i].tuiguangCommission+'元</span>'+
										'</div>'+
										'<div class="amount-info">'+
											'<div class="amount">'+
												'<span>预售<span>'+parseInt(platformActivityClassifyMsgs[i].productItem.stock+platformActivityClassifyMsgs[i].product.salesVolume)+'</span>件</span>'+
												'<span>仅剩'+platformActivityClassifyMsgs[i].productItem.stock+'件</span>'+
											'</div>'+
										'</div>'+
									'</div>'+
									'<p class="product-name text-2">'+
										platformActivityClassifyMsgs[i].product.productName+							
									'</p>'
				if(platformActivityClassifyMsgs[i].product.platformPrice<platformActivityClassifyMsgs[i].product.marketPrice){
							html = html +
									'<p class="product-price">'+
										'<span class="price f14">'+platformActivityClassifyMsgs[i].product.platformPrice+'</span>'+
										'<span class="discount floatRight">'+platformActivityClassifyMsgs[i].productItem.productItemDiscount+'折</span>'+
									'</p>'+
									'<p class="old-price">'+
										'<del>'+platformActivityClassifyMsgs[i].product.marketPrice+'元</del>'+
										'<span class="finished">已成交'+platformActivityClassifyMsgs[i].product.salesVolume+'件</span>'+
									'</p>'
				}else{
							html = html + 										
									'<p class="product-price">'+
										'<span class="price f14">'+platformActivityClassifyMsgs[i].product.platformPrice+'</span>'+
										'<span class="discount floatRight">'+platformActivityClassifyMsgs[i].productItem.productItemDiscount+'折</span>'+
									'</p>'+
									'<p class="old-price">'+
										'<span class="finished">已成交'+platformActivityClassifyMsgs[i].product.salesVolume+'件</span>'+
									'</p>'			
				}
				html = html +
							'</a>'+
							'</div>'+
						'</div>'
			}

			$(".productList").append(html);	
			FormatImg($(".p-img"),$(".p-img").parents(".product-img"));
		}
		buttom = false;
		$("#currentPage").attr("value",data.currentPage);
		$("#totalPage").attr("value",data.totalPage);
	},
	error:function(){
		$(".loading").hide();
		$(".slideToMore").show();
	}

});
}

//进入商品详情
$(".productList").on("click",".product",function(){
	var productId = $(this).attr("data-productId");
	var productType = $(this).attr("data-productType");
	var json = {
		"productId":productId	
	}
	var jsonStr = JSON.stringify(json);
	if(productType=="lingshou"){
		window.location.href = base_url + "customer/getProductDetail?jsonStr="+jsonStr;
	}else if(productType=="pingtuan"){
		window.location.href = base_url + "customer/getShopGroupProductDetailMsg?jsonStr="+jsonStr;
	}else if(productType=="zhekou"){
		window.location.href = base_url + "customer/getDiscountProductDetail?jsonStr="+jsonStr;
	}else if(productType=="zhongchou"){
		window.location.href = base_url + "customer/getCrowdFundingProductDetail?jsonStr="+jsonStr;
	}else if(productType=="miaosha"){
		window.location.href = base_url + "customer/getRushProductDetail?jsonStr="+jsonStr;
	}
	
});


